using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.TestDrivens;
using Pixysoft.Framework.Logs.Core;

namespace Pixysoft.Framework.Logs.TestCases
{
    [TestDriven(TestDrivenType.UnitTest, "SingletonLogger")]
    class UnitTest_004_SingletonLogger
    {
        private static IAssert assert = Assert.New(true);

        [TestStart]
        public static bool TestCaseStart()
        {
            return true;
        }

        [TestStop]
        public static void TestCaseStop()
        {
        }

        [TestStateSave]
        public static ITestDrivenDocument TestCaseStateSave()
        {
            return assert.Document;
        }

        [TestCase("Write")]
        public static void TestCase_001_Write()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory);
            string filename = "pixysoft";
            string postfix = ".txt";

            SingletonLogger.Write(path + filename + postfix, "helloworld");

            assert.IsTrue(SingletonLogger.HasFile(StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory), "pixysoft", ".txt"));

            assert.Write(SingletonLogger.Read(path + filename + postfix));

            assert.Write(SingletonLogger.Read(path, filename, postfix));

            SingletonLogger.Write(path, filename, postfix, "pixysoft");

            assert.IsTrue(SingletonLogger.HasFile(StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory), "pixysoft", ".txt"));

            assert.Write(SingletonLogger.Read(path + filename + postfix));

            assert.Write(SingletonLogger.Read(path, filename, postfix));
        }

        [TestCase("Insert")]
        public static void TestCase_003_Insert()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory);
            string filename = "pixysoft";
            string postfix = ".txt";

            assert.Write(SingletonLogger.Insert(path, filename, postfix, "hello"));
            assert.Write(SingletonLogger.Read(path, filename, postfix));

        }

        [TestCase("Append")]
        public static void TestCase_005_Append()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory);
            string filename = "pixysoft";
            string postfix = ".txt";

            assert.Write(SingletonLogger.Append(path, filename, postfix, "appendvalue"));
            assert.Write(SingletonLogger.Read(path, filename, postfix));

            assert.Write(SingletonLogger.Append(path, filename, postfix, "archivevalue", true));
            assert.Write(SingletonLogger.Read(path, filename, postfix));
        }

        [TestCase("Backup")]
        public static void TestCase_011_Backup()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory);
            string filename = "pixysoft";
            string postfix = ".txt";

            assert.Write(SingletonLogger.Append(path, filename, postfix, "appendvalue"));

            assert.IsTrue(SingletonLogger.Backup(path, filename, postfix));

        }

    }
}
